﻿
@using FFF.Test.Util.Consts;
@{
    ViewData["Title"] = "登录";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="keywords" content='easyui,jui,jquery easyui,easyui demo,easyui中文' />
    <meta name="description" content='YdmCore前端框架，基于最新版EasyUI前端框架构建，纯HTML调用功能组件，不用写JS代码的EasyUI，专注你的后端业务开发！' />
    <title>YdmCore - 用户登录</title>
    <!-- 浏览器标签图片 -->
    <link rel="shortcut icon" href="~/favicon.ico" />
    <link rel="stylesheet" href="~/lib/YdmJUI/static/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="~/lib/YdmJUI/static/plugins/font-awesome/css/font-awesome.min.css">
    <link href="~/css/Main/Home/Login/Login.css" rel="stylesheet" />
</head>
<body>
    <div class="box">
        <div class="login-box">
            <div class="login-title text-center">
                <span class="flag"><i class="fa fa-user"></i> 用户登陆</span>
                <h1>
                    <small><a href="https://www.kancloud.cn/yudaming/ydmcore/1077107" target="_blank" style="color:white">YdmCore框架</a></small>
                </h1>
            </div>
            <div class="login-content" id="LoginContainer">
                <div class="form">
                    <form id="modifyPassword" class="form-horizontal" action="#" method="post">
                        <input type="hidden" id="referer" name="referer" value="${param.referer}">
                        <div class="form-group">
                            <div class="col-xs-10 col-xs-offset-1">
                                <div class="input-group">
                                    <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                                    <input type="text" id="username" name="username" class="form-control" placeholder="用户名"
                                           value="ydm">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-10 col-xs-offset-1">
                                <div class="input-group">
                                    <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                                    <input type="password" id="password" name="password" class="form-control"
                                           placeholder="密码" value="123456">
                                </div>
                            </div>
                        </div>
                        <div class="form-group" id="formValidateCode" style="display:none">
                            <div class="col-xs-10 col-xs-offset-1">
                                <div class="input-group">
                                    <span class="input-group-addon"><span class="glyphicon glyphicon-eye-close"></span></span>
                                    <input type="text" class="form-control" placeholder="请输入图形验证码,点击图片可切换" style="width:270px" id="verificationCode" />
                                    <img src="/api/services/app/VerificationCode/GenVerificationCode" id="verifycode" onclick="chgVaidateCode()" />
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-10 col-xs-offset-1">
                                <div class="checkbox">
                                    <input id="chkRemeberPwd" class="styled" type="checkbox">
                                    <label for="chkRemeberPwd" style="color:white">
                                        记住密码
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group form-actions">
                            <div class="col-xs-12 text-center">
                                <button type="button" id="login" class="btn btn-sm btn-success">
                                    <span class="fa fa-check-circle"></span> 登录
                                </button>
                                <button type="button" id="reset" class="btn btn-sm btn-danger">
                                    <span class="fa fa-close"></span> 重置
                                </button>
                                <a href="/Home/Register" target="_blank" style="margin-left:10px;">去注册</a>
                                <a href="/Home/Forget" target="_blank" style="margin-left:10px;">忘记密码</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        @*<div class="logo-box">
                <img src="~/images/logo.png">
            </div>*@
    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-body">
                    <span class="text-danger"><i class="fa fa-warning"></i> 用户名或密码错误，请重试！</span>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">提示 </h4>
                </div>
                <div class="modal-body">
                    <p>检测到您正在使用IE浏览器</p>
                    <p style="font-weight:bold">
                        建议您使用chrome浏览器,将带来三倍以上的提速和站内通讯功能
                    </p>
                    <a href="~/down/chrome.exe" target="_blank">点我下载chrome浏览器</a>
                    <br />
                    <br />
                    如是360或者QQ浏览器可点击右上角使用极速模式浏览
                    <br />
                    <br />
                    <img src="~/images/chrome.png" height="150" width="300" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    @*<button type="button" class="btn btn-primary">提交更改</button>*@
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>

    <!-- 引入jQuery -->
    <!-- 引入jQuery -->
    <script src="~/lib/YdmJUI/static/plugins/jquery/jquery.min.js"></script>
    <script src="~/lib/YdmJUI/static/plugins/jquery/jquery.cookie.js"></script>
    <script src="~/lib/YdmJUI/static/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="~/lib/layer/layer.js"></script>
    <script src="~/lib/abp-web-resources/abp.js"></script>
    <script type="text/javascript" src="~/lib/abp-web-resources/libs/abp.jquery.js"></script>
    <script type="text/javascript" src="~/lib/abp-web-resources/libs/abp.layer.js"></script>
    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script src="~/lib/Ydm/Ydm.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="~/lib/YdmJUI/static/plugins/bootstrap/plugins/html5shiv.min.js"></script>
    <script src="~/lib/YdmJUI/static/plugins/bootstrap/plugins/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
        // 设置后端的AppConfig
        var appConfig = {
            PicDomain: '@AppConfigConsts.PicDomain',
            Apidomain:'@AppConfigConsts.ApiDomain'
        }
        $.dm.setAppConfig(appConfig);
        if (navigator.appName == "Microsoft Internet Explorer" &&
            (navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE6.0" ||
                navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE7.0" ||
                navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE8.0")
        ) {
            alert("您的浏览器版本过低，请使用360安全浏览器的极速模式或IE9.0以上版本的浏览器");
        }

        if (isIE()) {
            $('#myModal2').modal('show');
        }

        function isIE() {
            if (!!window.ActiveXObject || "ActiveXObject" in window)
                return true;
            else
                return false;
        }
    </script>
    <script type="text/javascript">
        $(function () {
            var formData = $.dm.getCookieObj("LoginFormData");
            if (formData) {
                $('#username').val(formData.userName);
                $('#password').val(formData.password);
            }

            $('body').keyup(function (event) {
                if (event.keyCode == "13") {
                    $("#login").trigger("click");
                    return false;
                }
            });

            $("#login").on("click", function () {
                submitForm();
            });

            function submitForm() {
                if (navigator.appName == "Microsoft Internet Explorer" &&
                    (navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE6.0" ||
                        navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE7.0" ||
                        navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE8.0")
                ) {
                    alert("您的浏览器版本过低，请使用360安全浏览器的极速模式或IE9.0以上版本的浏览器");
                } else {
                    var formData = {
                        userName: $('#username').val(),
                        password: $('#password').val(),
                        referer: $('#referer').val(),
                        verificationCode: $('#verificationCode').val()
                    };
                    var self = this;
                    var data = formData;
                    if (!data.userName || !data.userName) {
                        layer.msg($.dm.L("用户名和密码不能为空"));
                        return;
                    }
                    var options = {
                        url: '/api/services/app/FWUser/UserLogin',
                        data: data,
                        noNeedToken:true,
                        error: function () {
                            $("#login").text("登录");
                            $("#login").removeAttr("disabled");
                        }
                    };
                    $("#login").text("登录中...");
                    $("#login").attr("disabled", "disabled");
                    var success = function (result) {
                        if (result.loginDto) {
                            // 如果是记住用户名和密码那么需要记住
                            if ($("#chkRemeberPwd").get(0).checked) {
                                var data = {
                                    userName: $('#username').val(),
                                    password: result.loginDto.userPwdEncry
                                };
                                $.dm.setCookie("LoginFormData", JSON.stringify(data), 14);
                            }

                            // 登录成功记录cookie
                            $.dm.setUserInfo(result.loginDto);
                           

                            // 初始化选中的系统和公司
                            var applicationInfo = {
                                id: result.loginDto.defaultApplicationGUID
                            };
                            $.dm.setAppInfo(applicationInfo);

                            var buInfo = {
                                id: result.loginDto.defaultBuUnitGUID,
                            };

                            $.dm.setBuinfo(buInfo);

                            var redit = $.dm.getQueryString("redirct");
                            if (redit) {
                                redit = unescape(redit);
                                window.location.href = redit;
                            } else {
                                window.location.href = "/";
                            }
                        }
                        else {
                            layer.msg(result.errorMsg);
                            $("#login").text("登录");
                            $("#login").removeAttr("disabled");
                            if (result.isNeedValidateCode === true) {
                                chgVaidateCode();
                                $("#formValidateCode").show();
                                $("#LoginContainer").css("height", "320px");
                            }
                        }
                    }
                    abp.ajax(options).done(success);
                }
            }

            $("#reset").on("click", function () {
                $("#username").val("");
                $("#password").val("");
            });
        });

        function chgVaidateCode() {
            $("#verifycode").get(0).src = "/api/services/app/VerificationCode/GenVerificationCode?rnd=" + Math.floor(Math.random() * 10000);
        }

    </script>
</body>
</html>
